YF <- readRDS("../data_clean/YFcases/YFlong.rds")
brazil <- st_read("../data_clean", "BRAZpolygons")
## Reading layer `BRAZpolygons' from data source `/Users/renikaul/Documents/YF_Brazil/data_clean' using driver `ESRI Shapefile'
## Simple feature collection with 5561 features and 2 fields
## geometry type: MULTIPOLYGON
## dimension: XY
## bbox: xmin: -73.99442 ymin: -33.75206 xmax: -28.83588 ymax: 5.271807
## epsg (SRID): 4326
## proj4string: +proj=longlat +datum=WGS84 +no_defs
Map of Number of Cases per Muni from 2001-2014
# calculate total cases per muni
totCase <- YF %>%
group_by(muni.no) %>%
filter(!is.na(case)) %>%
summarise(totalCases=sum(case, na.rm=T), totalMonths = n_distinct(month.no))
# add to shapefile
brazilYF <- merge(brazil, totCase, by.y="muni.no", by.x = "muni_no", all.x = T)
#create color palette
colpal <- colorBin("YlOrRd", domain = c(1,21), bins = c(1,2,3,4,5,10,15,21))
#create popups
casePop <- paste0(brazilYF$muni_name,
"<br><strong>", brazilYF$totalCases,
"</strong> Cases from 2001-2014.")
leaflet(data=brazilYF) %>%
addPolygons(color = "#444444", weight = 0.1, smoothFactor = 0.5,
opacity = 1.0, fillOpacity = 0.75,
fillColor = ~colpal(totalCases),
highlightOptions = highlightOptions(color = "white", weight = 2,
bringToFront = TRUE),
popup=casePop) %>%
addProviderTiles(providers$CartoDB.Positron)